<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{margin: 0;padding: 0;}
        #nav{
            width: 100%;
            height: 40px;
            background-color: red;
            position: fixed;
            top: -40px;
            transition: 3s;
        }
    </style>
</head>
<body style="height: 1000px;">
    <div id="nav">手机 手表 电脑 键盘 鼠标</div>
    <script>
        var onav=document.getElementById("nav");
        window.onscroll=function(){
            var getScrollTop=document.documentElement.scrollTop;
            console.log(getScrollTop);
            if(getScrollTop>200){
                onav.style.top=0
            }else{
                onav.style.top="-40px"
            }
        }
    </script>
</body>
</html>